/**
 * @(#) OverView.as
 *
 * @date		2009. 04. 20.
 * @version		1.0
 * @author		Jo, ChangHun
 * @description	연말정산 메인 view - Mediator
 * 				연말정산 - 탭11 기타소득공제 Presentation Logic을 관리 
 */
package com.skt.common_hr.yearadjustment.view
{
	import com.skt.common_hr.yearadjustment.model.vo.OtherSubtractionMoneyVO;
	import com.skt.common_hr.yearadjustment.view.components.YearAdjustmentView;
	import com.skt.common_hr.yearadjustment.view.components.popOtherSubtraction2014;
	import com.skt.common_hr.yearadjustment.view.components.reqOtherSubtraction;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	import mx.core.IFlexDisplayObject;
	import mx.managers.PopUpManager;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	

	public class reqOtherSubtractionMediator extends Mediator
	{
		public static const NAME:String = "reqOtherSubtractionMediator"; 



		/**
		* 생성자
		* 
		* @param
		* @return void
		*/
        public function reqOtherSubtractionMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
            view.callLater(initView);
        }
 		
		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		*/
 		public function initView():void
 		{
 			view.addEventListener(reqOtherSubtraction.OTHER_POPUP_OPEN, onOtherPopupOpen);
 			view.addEventListener(reqOtherSubtraction.OTHER_EDIT_CHACK, onOtherEditChack);
 		}
 		
 		private function onOtherPopupOpen(event:Event):void
 		{
 			var center:Sprite = Sprite(mx.core.Application.application);
 			
 			var popMediator:popOtherSubtraction2014Mediator = facade.retrieveMediator(popOtherSubtraction2014Mediator.NAME) as popOtherSubtraction2014Mediator;
 			if(!popMediator) {
 				facade.removeMediator(popOtherSubtraction2014Mediator.NAME);
 			}

 			var popOtherView:IFlexDisplayObject = PopUpManager.createPopUp(center, popOtherSubtraction2014, true);
 			PopUpManager.centerPopUp(popOtherView);
 			
 			popMediator = new popOtherSubtraction2014Mediator(popOtherView);
 			facade.registerMediator(popMediator);
 			
 			popMediator.v_year = view._selYear;
 			popMediator.v_enable = view._isEnable;

 		}
 		
 		private function onOtherEditChack(event:Event):void
 		{
 			facade.sendNotification(YearAdjustmentView.CHECK_REQ_OTHERSUBTRACTION, null);
 		}
 		
 		

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		* 
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array 
		{
			return [
				YearAdjustmentView.CHECK_REQ_OTHERSUBTRACTION
					];
		}
		

		/**
		* Noti별로 처리한다.
		* 
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
						
			switch(note.getName()) 
			{
				case YearAdjustmentView.CHECK_REQ_OTHERSUBTRACTION:
					if(note.getBody() != null) {	// null이 아니면 pop에서 온 메세지
						var amounts:Array;
						var tmp:OtherSubtractionMoneyVO;
						amounts = (note.getBody() as Array);
						tmp = view._otherVo.clone();
						tmp.LTSF1 = amounts[0];
						tmp.LTSF2 = amounts[1];
						tmp.LTSF3 = amounts[2];
						view._otherVo = tmp;
					}					
					break;
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}
 		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Utility Functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
        private function get view():reqOtherSubtraction
        {
            return viewComponent as reqOtherSubtraction;
        }
	}
}